﻿/*
	***Copyright 2012, Gabriel Valentoni Guelfi***
	
	
	This file is part of GWebDev Actionscript API.
	
	GWebDev Actionscript API is a free software; you can redistribute it
 	and/or modify it within the terms of General Public License GNU the way it was released by Free Software Foundation.
	
	This program is distributed with the hope that can be useful, but UNWARRANTED; without implicit warranties of adequation
	to any market or application in particular. See the General Public License GNU for more details.
	
	You shall has received a copy of the General Public License GNU along with this software within a file named "license.txt", 
	if you hasn´t, please, subscribe to Free Software Foundation Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110-1301, USA.
	Or contact the author trough the e-mail address listed below.

*/

////// GWebDev Actionscript API //////
//
// Version: 0.1
// Author: Gabriel Valentoni Guelfi
// E-mail: gabriel.valguelfi@gmail.com
//
//////

package gwdflash.style{
	import flash.text.TextFormat;

	public class Style extends Object{
		
		public var width:Number;
		public var height:Number;
		public var x:Number;
		public var y:Number;
		public var color:Number;
		public var backgroundColor:Number;
		public var borderColor:Number;
		public var borderThickness:Number;
		private var _margin:Object;
		private var _padding:Object;
		private var _defaultTextFormat:TextFormat;
		
		public function Style(_width:Number = NaN, _height:Number = NaN, _x:Number = NaN, _y:Number = NaN, _color:Number = NaN, _backgroundColor:Number = NaN, _borderColor:Number = NaN, _borderThickness = NaN, margin = null, padding = null, textFormat:TextFormat = null) {
			width = _width;
			height = _height;
			x = _x;
			y = _y;
			backgroundColor = _backgroundColor;
			color = _color;
			borderColor = _borderColor;
			borderThickness = _borderThickness;
			
			if(margin != null){
				_margin = new Object();
				if(margin is Number){
					_margin.top = margin;
					_margin.right = margin;
					_margin.bottom = margin;
					_margin.left = margin;
				} else if(margin is Object){
					for(var key:String in margin){
						if(key != 'top' && key != 'right' && key != 'bottom' && key != 'left' || !(margin[key] is Number)){
							trace("From Class Style, Error: margin objects just accept the properties: top, right, bottom and left, whose values must be numbers.");
						} else {
							_margin[key] = margin[key];
						}
					}
				}
			}
			
			if(padding != null) {
				_padding = new Object();
				if(padding is Number){
					_padding.top = padding;
					_padding.right = padding;
					_padding.bottom = padding;
					_padding.left = padding;
				} else if(padding is Object){
					for(var k:String in padding){
						if(k != 'top' && k != 'right' && k != 'bottom' && k != 'left' || !(padding[k] is Number)){
							trace("From Class Style, Error: padding objects just accept the properties: top, right, bottom and left, whose values must be numbers.");
						} else {
							_padding[k] = padding[k];
						}
					}
				}
			}
			
			if(textFormat != null){
				defaultTextFormat = TextFormat(textFormat);
			}
		}
		
		public function set margin(marginValue):void{
			_margin = new Object();
			if(marginValue is Number){
				_margin.top = marginValue;
				_margin.right = marginValue;
				_margin.bottom = marginValue;
				_margin.left = marginValue;
			} else if(marginValue is Object){
				for(var key:String in marginValue){
					if(key != 'top' && key != 'right' && key != 'bottom' && key != 'left' || !(marginValue[key] is Number)){
						trace("From Class Style, Error: margin objects just accept the properties: top, right, bottom and left, whose values must be numbers.");
					} else {
						_margin[key] = marginValue[key];
					}
				}
			}
		}
		
		public function get margin():*{
			if(_margin.top == _margin.right && _margin.right == _margin.bottom && _margin.bottom == _margin.left){
				return _margin.top;
			} else {
				return _margin;
			}
		}
		
		public function set padding(paddingValue):void{
			_padding = new Object();
			if(paddingValue is Number){
				_padding.top = paddingValue;
				_padding.right = paddingValue;
				_padding.bottom = paddingValue;
				_padding.left = paddingValue;
			} else if(paddingValue is Object){
				for(var key:String in paddingValue){
					if(key != 'top' && key != 'right' && key != 'bottom' && key != 'left' || !(paddingValue[key] is Number)){
						trace("From Class Style, Error: margin objects just accept the properties: top, right, bottom and left, whose values must be numbers.");
					} else {
						_padding[key] = paddingValue[key];
					}
				}
			}
		}
		
		public function get padding():*{
			if(_padding.top == _padding.right && _padding.right == _padding.bottom && _padding.bottom == _padding.left){
				return _padding.top;
			} else {
				return _padding;
			}
		}
		
		public function set defaultTextFormat(_textFormat:TextFormat):void{
			_defaultTextFormat = TextFormat(_textFormat);
		}
		
		public function get defaultTextFormat():TextFormat {
			return _defaultTextFormat;
		}
	}
}